package com.circle.search;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;

/**
 * Hello world!
 *
 */
public class App 
{
	public final static String clusterHosts="10.10.76.177";
	
	public static TransportClient client;

	public static void main(String[] args) {
		Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "uc_es").build();
		client = new TransportClient(settings);
		String[] hostslist = clusterHosts.split(",");
		for (String h : hostslist) {
			client.addTransportAddress(new InetSocketTransportAddress(h, 9300));
		}
		Set<String> uidSet = new HashSet<String>();  
		String uids = "";
		QueryBuilder urlQuery = QueryBuilders.termQuery("passport", "0015AC64BD90ED2FA8C577F5995A019D@qq.sohu.com@qq.sohu.com");
		SearchResponse searchResponse = client.prepareSearch("movieuc_filter_2016-12-07").setTypes("movieuc_filter")
				.setQuery(urlQuery).setSize(100).execute().actionGet();
		SearchHits searchHits = searchResponse.getHits();
		for (SearchHit searchHit : searchHits) {
			String uid = (String) searchHit.getSource().get("uid");
			System.out.println(uid);
			uidSet.add(uid);
			System.out.println("36F9EE8D7F9A4882F421712B6A3C33DD@qq.sohu.com 对应的uid" + uid);
		}
		
		uids = StringUtils.join(uidSet.toArray(), ";");
		System.out.println("uids: " + uids);
		System.out.println("ids.size() :" + searchHits.getTotalHits());

	}
    
    
	
    
}
